package sixkey.config.satokenconfig;

/**
 * ClassName:StpInterfaceImpl
 * Package:sixkey.config.satokenconfig
 * Description
 *
 * @Author:@wenxueshi
 * @Create:2023/5/21 - 0:45
 * @Version:v1.0
 */

import cn.dev33.satoken.session.SaSession;
import cn.dev33.satoken.stp.StpInterface;
import cn.dev33.satoken.stp.StpUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import sixkey.mapper.MenuMapper;
import sixkey.mapper.RoleMapper;
import sixkey.service.IMenuService;
import sixkey.service.IRoleService;

import java.util.List;

/**
 * 自定义权限验证接口扩展
 */
@Component    // 保证此类被SpringBoot扫描，完成Sa-Token的自定义权限验证扩展
@RequiredArgsConstructor
public class StpInterfaceImpl implements StpInterface {

    private final MenuMapper menuMapper;

    private final RoleMapper roleMapper;


    /**
     * 返回一个账号所拥有的权限码集合
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        return menuMapper.getMenuByUserId(loginId);
    }

    /**
     * 返回一个账号所拥有的角色标识集合 (权限与角色可分开校验)
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        return roleMapper.getRoleByUserId(loginId);
    }
}
